package com.sneakxy.mybase4j.platform.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.sneakxy.mybase4j.base.service.BaseService;
import com.sneakxy.mybase4j.platform.beans.Dict;
import com.sneakxy.mybase4j.platform.provider.IDictProvider;
import com.sneakxy.mybatis.commons.repository.query.domain.CriteriaBuilder;

/**
 * 
 * @author 潜行的青衣
 * @see
 */
@Service
public class DictService extends BaseService<Dict, String, IDictProvider> implements IDictService {

	@Reference(version = "1.0.0")
	@Autowired(required = false)
	@Qualifier("dictProvider")
	private IDictProvider provider;

	@Override
	public IDictProvider getProvider() {
		return this.provider;
	}

	/* (non-Javadoc)
	 * @see com.sneakxy.mybase4j.platform.service.IDictService#findByType(java.lang.String, java.lang.String, boolean)
	 */
	@Override
	public Dict findByType(String parent_id, String value, boolean children) {
		return this.getProvider().findByType(parent_id, value, children);
	}

	/* (non-Javadoc)
	 * @see com.sneakxy.mybase4j.platform.service.IDictService#findByType(java.lang.String, boolean)
	 */
	@Override
	public Dict findByType(String value, boolean children) {
		return this.findByType(null, value, children);
	}

	/* (non-Javadoc)
	 * @see com.sneakxy.mybase4j.platform.service.IDictService#findDicts(java.lang.String, boolean)
	 */
	@Override
	public List<Dict> findDicts(String parent_id, boolean children) {
		return this.getProvider().findDicts(parent_id, children);
	}

	/* (non-Javadoc)
	 * @see com.sneakxy.mybase4j.platform.service.IDictService#findByValues(java.lang.String[], boolean)
	 */
	@Override
	public Dict findByValues(String[] values, boolean children) {
		return this.getProvider().findByValues(values, children);
	}

	/* (non-Javadoc)
	 * @see com.sneakxy.mybase4j.platform.service.IDictService#findBySearch(java.lang.String, java.lang.String, org.springframework.data.domain.Pageable)
	 */
	@Override
	public Page<Dict> findBySearch(String parent_id, String search, Pageable pageable) {
		return this.getProvider().findBySearch(parent_id, search, pageable);
	}

	/* (non-Javadoc)
	 * @see com.sneakxy.mybase4j.platform.service.IDictService#hasChildren(java.lang.String)
	 */
	@Override
	public boolean hasChildren(String id) {
		CriteriaBuilder<Dict> builder = new CriteriaBuilder<Dict>(Dict.class);
		builder.andEq("parentId", id);
		return this.getProvider().count(builder.build()) > 0;
	}

}
